package routers

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"github.com/gofiber/fiber/v2/middleware/logger"
	"github.com/gofiber/template/html/v2"
)

func New() *fiber.App {
	engine := html.New("./resource/dist", ".html")
	app := fiber.New(fiber.Config{
		Views: engine,
	})

	// TODO 使用 logger 中间件
	app.Use(logger.New(logger.Config{
		Format:     "${pid} ${status} - ${method} ${path}\n",
		TimeFormat: "02-Jan-2006",
		TimeZone:   "Asia/Shanghai",
	}))
	app.Static("/", "./resource/dist")
	app.Get("/", func(c *fiber.Ctx) error {
		return c.Render("index", nil)
	})
	// app.Static("/", "./upload")
	// app.Static("/", "./resource/stations")
	v1 := app.Group("/api/v1")
	v1.Use(cors.New()) // 允许跨域

	v1.Get("/hello", func(c *fiber.Ctx) error {
		return c.SendString("Hello, World!")
	})

	return app
}
